package com.cyzy.service.impl;

import com.cyzy.domain.dto.ResponseData;
import com.cyzy.domain.query.TCultivationQuery;
import com.cyzy.domain.vo.TCultivation;
import com.cyzy.domain.vo.TLog;
import com.cyzy.mapper.CultivationMapper;
import com.cyzy.mapper.LogMapper;
import com.cyzy.service.CultivationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CultivationImpl implements CultivationService {
//    种植
    @Autowired
    private CultivationMapper cultivationMapper;
//    日志操作记录
    @Autowired
    private LogMapper logMapper;
//    害虫服务
    @Override
    public ResponseData pest(TCultivationQuery tCultivationQuery) {
        TCultivation tCultivation = cultivationMapper.selectById(tCultivationQuery.getCultivationId());
// 判断是否有 pet，如果有则更新 pet  杀虫操作
        if (tCultivationQuery.getPet() != null) {
            tCultivation.setPet(tCultivationQuery.getPet());
            cultivationMapper.updateById(tCultivation);
//            插入日志操作  驱虫日志
            TLog tLog = new TLog();
            tLog.setOperation("驱虫");
            tLog.setLandId(tCultivationQuery.getLid());
            tLog.setUserId(tCultivationQuery.getUid());
            logMapper.insert(tLog);
        }

// 判断是否有 growp，如果有则更新 growp
        if (tCultivationQuery.getGrowp() != null) {
            tCultivation.setGrowp(tCultivationQuery.getGrowp());
            cultivationMapper.updateById(tCultivation);
            //            插入日志操作  施肥
            TLog tLog = new TLog();
            tLog.setOperation("施肥");
            tLog.setLandId(tCultivationQuery.getLid());
            tLog.setUserId(tCultivationQuery.getUid());
            logMapper.insert(tLog);
        }

// 更新数据
        ResponseData responseData = new ResponseData();
        responseData.setCode(200);
        return responseData;
    }
}
